﻿/**
 * ...
 * @author	Kliment
 * @version	1.0.5
 */
class kliment.data.Time {
	private var _body:Number
	private var _milliseconds:Number;
	private var _seconds:Number;
	private var _minutes:Number;
	private var _hours:Number;
	private var _days:Number;
	
	public function Time(milliseconds:Number) {
		_body = milliseconds || 0;
		
		var temp:Number = _body / 1000;
		
		_days = Math.floor(temp / (60 * 60 * 24));
		temp -= _days * 60 * 60 * 24;
		
		_hours = Math.floor(temp / (60 * 60));
		temp -= _hours * 60 * 60;
		
		_minutes = Math.floor(temp / 60);
		temp -= _minutes * 60;
		
		_seconds = Math.floor(temp);
		temp -= _seconds;
		
		_milliseconds = Math.floor(temp * 1000);
	}
	
	public function getMilliseconds():Number {
		return _body;
	}
	
	public function getSeconds():Number {
		return Math.floor(_body  / 1000);
	}
	
	public function getMinutes():Number {
		return Math.floor(_body / (1000 * 60));
	}
	
	public function getHours():Number {
		return Math.floor(_body / (1000 * 60 * 60));
	}
	
	public function getDays():Number {
		return Math.floor(_body / (1000 * 60 * 60 * 24));;
	}
	
	public function get milliseconds():Number { return _milliseconds; }
	/*public function set milliseconds(value:Number):Void {
		_milliseconds = value;
	}*/
	
	public function get seconds():Number { return _seconds; }
	/*public function set seconds(value:Number):Void {
		_seconds = value;
	}*/
	
	public function get minutes():Number { return _minutes; }
	/*public function set minutes(value:Number):Void {
		_minutes = value;
	}*/
	
	public function get hours():Number { return _hours; }
	/*public function set hours(value:Number):Void {
		_hours = value;
	}*/
	
	public function get days():Number { return _days; }
	/*public function set days(value:Number):Void {
		_days = value;
	}*/
	
	public function toString(delimer:String):String {
		var result:Array = new Array();
		if (_days > 0) result.push(_days);
		if (_hours > 0) result.push(_hours);
		if (_minutes > 0) result.push(_minutes);
		if (_seconds > 0) result.push(_seconds);
		if (_milliseconds > 0) result.push(_milliseconds);
		return result.join(delimer);
	}
	
}